//package com.fingard.dsp.bank.directbank.ccb04;
//
//import com.fingard.constant.Format;
//import com.fingard.dsp.bank.directbank.bankInterface.IContract;
//import com.fingard.dsp.bank.reqrespobj.contract.*;
//import com.fingard.dsp.bank.reqrespobj.contract.detail.RetAtsContractDetail;
//import com.fingard.text.StringHelper;
//import com.fingard.xml.XmlTextReader;
//import com.fingard.xml.XmlTextWriter;
//
//import java.io.File;
//import java.util.Date;
//
//public class CCB04Contract extends CCB04Base implements IContract {
//    @Override
//    public RetAtsContract contract(ReqContract p_req) throws Exception {
//        RetAtsContract retAts = new RetAtsContract(p_req.reqHeader);
//        RetAtsContractDetail tmpRetDetail;
//        tmpRetDetail = singleContract(p_req, retAts);
//        if (tmpRetDetail.respCode.equals("-1") && StringHelper.isNullOrEmpty(tmpRetDetail.reqSeqID)) {
//            tmpRetDetail.reqSeqID = p_req.contractDetail.askNumber;
//        }
//        retAts.writeRetDetail(tmpRetDetail);
//        return retAts;
//    }
//
//    @Override
//    public RetAtsContract upContract(ReqContract p_req) throws Exception {
//        return null;
//    }
//
//    public RetAtsContractDetail singleContract(ReqContract p_req, RetAtsContract retAts) throws Exception {
//        RetAtsContractDetail tmpRetDetail = new RetAtsContractDetail();
//        getBnkToken();
////        if (triDesKeys != null && triDesKeys.length != 1024) {
//        if (StringHelper.hasAnyChar(bankFront.token)) {
//            if (new File(String.format("%1$s%2$s_BnkPubKey.txt", strtmpFile, bankFront.org)).exists()) {
//                if (!"".equals(bankFront.loginFlag) && !"false".equals(bankFront.loginFlag)) {
//                    transfer(p_req, tmpRetDetail, retAts);
//                } else {
//                    tmpRetDetail.respCode = "-1";
//                    tmpRetDetail.respInfo = "签到失败";
//                }
//            } else {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = "下载银行pub密钥失败";
//            }
//        } else {
//            tmpRetDetail.respCode = "-1";
//            tmpRetDetail.respInfo = "下载银行3des密钥失败";
//        }
//        return tmpRetDetail;
//    }
//
//    public RetAtsContractDetail transfer(ReqContract p_req, RetAtsContractDetail tmpRetDetail, RetAtsContract retAts) throws Exception {
//        txCode = "P1CLPT960";
//        reqSeqID = p_req.contractDetail.askNumber;
//        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//        XmlTextWriter xmlWriterWithoutCDATA = new XmlTextWriter();//发银行报文的XML对象
//        //写入通用的头部节点
//        writeCommonHeaderWithoutCDATA(xmlWriterWithoutCDATA);
//        String CustNo = bankFront.org;
//        String projectID = getBankConfig().getMapValueByKey("projectIDMapping", p_req.reqHeader.transType);
//        xmlWriterWithoutCDATA.writeStartElement("request");
//        xmlWriterWithoutCDATA.writeElementString("EBnk_SvAr_ID", CustNo);
//        xmlWriterWithoutCDATA.writeElementString("Entrst_Prj_ID", projectID);
//        xmlWriterWithoutCDATA.writeElementString("Mnplt_TpCd", "0");
//        xmlWriterWithoutCDATA.writeElementString("SRP_Cst_TpCd", "1");
//        //0-本行客户，1-他行客户
//        if (StringHelper.isNullOrEmpty(p_req.contractDetail.sameBnk)) {
//            xmlWriterWithoutCDATA.writeElementString("OurBnk_OBnk_Ind", "");
//        } else {
//            if ("1".equals(p_req.contractDetail.sameBnk)) {
//                xmlWriterWithoutCDATA.writeElementString("OurBnk_OBnk_Ind", "0");
//            } else {
//                xmlWriterWithoutCDATA.writeElementString("OurBnk_OBnk_Ind", "1");
//            }
//        }
//        xmlWriterWithoutCDATA.writeElementString("TrdPCt_AccNo", p_req.contractDetail.payAct);
//        xmlWriterWithoutCDATA.writeElementString("Acc_AccNm", p_req.contractDetail.payName);
//        xmlWriterWithoutCDATA.writeElementString("TrdPCt_Crdt_No", p_req.contractDetail.certNum);
//        xmlWriterWithoutCDATA.writeElementString("TrdPCt_Crdt_TpCd", convertCertTypeToBank(p_req.contractDetail.certType));
//        xmlWriterWithoutCDATA.writeElementString("TrdPCt_ID_Fst_ID", "");
//        xmlWriterWithoutCDATA.writeElementString("TrdPCt_ID_Snd_ID", "");
//        xmlWriterWithoutCDATA.writeElementString("MblPh_No", p_req.contractDetail.cellPhone);
//        if (getBankConfig().getValueAsBool("useConigureTime")) {
//            String configureTime = getBankConfig().getValueAsString("configureTime");
//            if (StringHelper.hasAnyChar(configureTime)) {
//                xmlWriterWithoutCDATA.writeElementString("StrtUs_Dt", Format.Date8Format.format(Format.Date8Format.parse(configureTime)));
//            } else {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = "config中configureTime配置为空，请检查'configureTime'的配置！";
//                return tmpRetDetail;
//            }
//        } else {
//            xmlWriterWithoutCDATA.writeElementString("StrtUs_Dt", Format.Date8Format.format(new Date()));
//        }
//        String deadLine = p_req.contractDetail.deadLine;
//        if (StringHelper.isNullOrEmpty(deadLine)) {
//            deadLine = getBankConfig().getMapValueByKey("contractKeyMapping", "deadLine");
//            if (StringHelper.isNullOrEmpty(deadLine)) {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = "缺失配置节点'deadLine'或值为空!";
//                return tmpRetDetail;
//            }
//        }
//        xmlWriterWithoutCDATA.writeElementString("Vld_CODt", deadLine);
//        String singleLimit = p_req.contractDetail.singleLimit;
//        if (StringHelper.isNullOrEmpty(singleLimit)) {
//            singleLimit = getBankConfig().getMapValueByKey("contractKeyMapping", "singleLimit");
//            if (StringHelper.isNullOrEmpty(singleLimit)) {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = "缺失配置节点'singleLimit'或值为空!";
//                return tmpRetDetail;
//            }
//        }
//        xmlWriterWithoutCDATA.writeElementString("Per_Txn_Qot", singleLimit);
//        xmlWriterWithoutCDATA.writeEndDocument();
//
//        int n = xmlWriterWithoutCDATA.toXmlString().length();
//        xmlLength = decimalFormat.format(n);
//
//        writeCommonHeader(xmlWriter);
//        xmlWriter.writeStartElement("request");
//        xmlWriter.writeElementCDATA("EBnk_SvAr_ID", CustNo);
//        xmlWriter.writeElementCDATA("Entrst_Prj_ID", projectID);
//        xmlWriter.writeElementCDATA("Mnplt_TpCd", "0");
//        xmlWriter.writeElementCDATA("SRP_Cst_TpCd", "1");
//        if (StringHelper.isNullOrEmpty(p_req.contractDetail.sameBnk)) {
//            xmlWriterWithoutCDATA.writeElementString("OurBnk_OBnk_Ind", "");
//        } else {
//            if ("1".equals(p_req.contractDetail.sameBnk)) {
//                xmlWriterWithoutCDATA.writeElementString("OurBnk_OBnk_Ind", "0");
//            } else {
//                xmlWriterWithoutCDATA.writeElementString("OurBnk_OBnk_Ind", "1");
//            }
//        }
//        xmlWriter.writeElementCDATA("TrdPCt_AccNo", p_req.contractDetail.payAct);
//        xmlWriter.writeElementCDATA("Acc_AccNm", p_req.contractDetail.payName);
//        xmlWriter.writeElementCDATA("TrdPCt_Crdt_No", p_req.contractDetail.certNum);
//        xmlWriter.writeElementCDATA("TrdPCt_Crdt_TpCd", convertCertTypeToBank(p_req.contractDetail.certType));
//        xmlWriter.writeElementCDATA("TrdPCt_ID_Fst_ID", "");
//        xmlWriter.writeElementCDATA("TrdPCt_ID_Snd_ID", "");
//        xmlWriter.writeElementCDATA("MblPh_No", p_req.contractDetail.cellPhone);
//        if (getBankConfig().getValueAsBool("useConigureTime")) {
//            String configureTime = getBankConfig().getValueAsString("configureTime");
//            if (StringHelper.hasAnyChar(configureTime)) {
//                xmlWriterWithoutCDATA.writeElementString("StrtUs_Dt", Format.Date8Format.format(Format.Date8Format.parse(configureTime)));
//            } else {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = "config中configureTime配置为空，请检查'configureTime'的配置！";
//                return tmpRetDetail;
//            }
//        } else {
//            xmlWriterWithoutCDATA.writeElementString("StrtUs_Dt", Format.Date8Format.format(new Date()));
//        }
//        xmlWriter.writeElementCDATA("Vld_CODt", deadLine);
//        xmlWriter.writeElementCDATA("Per_Txn_Qot", singleLimit);
//        xmlWriter.writeEndDocument();
//
//        String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//        if (tmpStrRet[0].length() == 0) {
//            StringBuilder tmpSbMsg = new StringBuilder();
//            XmlTextReader tmpBkReader = null;
//            tmpBkReader = getBankInfo(tmpStrRet[1], tmpSbMsg);
//            String xln_status = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_TX_STATUS"); // 服务状态
//            String xln_resp_code = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_RESP_CODE"); // 服务响应码
//            String xln_resp_desc = tmpBkReader.getFirstText("/Transaction/Transaction_Header/SYS_RESP_DESC"); // 服务响应描述
//            if (IsResultInvlid(tmpStrRet[1], tmpBkReader, false, retAts)) {
//                String Sign_Rslt = tmpBkReader.getFirstText("/Transaction/Transaction_Body/response/Sign_Rslt");
//                String FalRs = tmpBkReader.getFirstText("/Transaction/Transaction_Body/response/FalRs");
//                tmpRetDetail.respInfo = FalRs;
//                if ("0".equals(Sign_Rslt)) {
//                    tmpRetDetail.respCode = "0";
//                    tmpRetDetail.signConfirmType = "3";
//                    tmpRetDetail.signState = ContractState.SUCCESS;
//                } else {
//                    tmpRetDetail.respCode = "-1";
//                    tmpRetDetail.signState = ContractState.FAIL;
//                }
//            } else {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = xln_status + xln_resp_code + xln_resp_desc;
//            }
//        } else {
//            tmpRetDetail.respCode = "-1";
//            tmpRetDetail.respInfo = tmpStrRet[1];
//        }
//        return tmpRetDetail;
//    }
//
//    @Override
//    public RetAtsContract qryContract(ReqContract p_reqQry) throws Exception {
//        RetAtsContract retAts = new RetAtsContract(p_reqQry.reqHeader);
//        RetAtsContractDetail tmpRetDetail = new RetAtsContractDetail();
//        tmpRetDetail.reqSeqID = p_reqQry.contractDetail.askNumber;
//        getBnkToken();
//        if (StringHelper.hasAnyChar(bankFront.token)) {
//            if (new File(String.format("%1$s%2$s_BnkPubKey.txt", strtmpFile, bankFront.org)).exists()) {
//                if (!"".equals(bankFront.loginFlag) && !"false".equals(bankFront.loginFlag)) {
//                    txCode = "P1CMSTP15";
//                    reqSeqID = getQryTransID();
//                    XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//                    XmlTextWriter xmlWriterWithoutCDATA = new XmlTextWriter();//发银行报文的XML对象
//                    //写入通用的头部节点
//                    writeCommonHeaderWithoutCDATA(xmlWriterWithoutCDATA);
//                    String projectID = getBankConfig().getMapValueByKey("projectIDMapping", p_reqQry.reqHeader.transType);
//                    xmlWriterWithoutCDATA.writeStartElement("request");
//                    xmlWriterWithoutCDATA.writeElementString("TrdPCt_AccNo", p_reqQry.contractDetail.payAct);
//                    xmlWriterWithoutCDATA.writeElementString("Crdt_TpCd", "");
//                    xmlWriterWithoutCDATA.writeElementString("Crdt_No", "");
//                    xmlWriterWithoutCDATA.writeElementString("Entrst_Prj_ID", projectID);
//                    xmlWriterWithoutCDATA.writeElementString("Entrst_Prj_Nm", "");
//                    xmlWriterWithoutCDATA.writeElementString("TrdPCt_ID_Fst_ID", "");
//                    xmlWriterWithoutCDATA.writeElementString("SRP_AR_StCd", "");
//                    xmlWriterWithoutCDATA.writeEndDocument();
//                    int n = xmlWriterWithoutCDATA.toXmlString().length();
//                    xmlLength = decimalFormat.format(n);
//
//                    writeCommonHeader(xmlWriter);
//                    xmlWriter.writeStartElement("request");
//                    xmlWriter.writeElementCDATA("TrdPCt_AccNo", p_reqQry.contractDetail.payAct);
//                    xmlWriter.writeElementCDATA("Crdt_TpCd", "");
//                    xmlWriter.writeElementCDATA("Crdt_No", "");
//                    xmlWriter.writeElementCDATA("Entrst_Prj_ID", projectID);
//                    xmlWriter.writeElementCDATA("Entrst_Prj_Nm", "");
//                    xmlWriter.writeElementCDATA("TrdPCt_ID_Fst_ID", "");
//                    xmlWriter.writeElementCDATA("SRP_AR_StCd", "");
//                    xmlWriter.writeEndDocument();
//                    try {
//                        String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//                        if (tmpStrRet[0].length() == 0) {
//                            StringBuilder tmpSbMsg = new StringBuilder();
//                            XmlTextReader tmpBkReader = null;
//                            tmpBkReader = getBankInfo(tmpStrRet[1], tmpSbMsg);
//                            if (IsResultInvlid(tmpStrRet[1], tmpBkReader, false, retAts)) {
//                                tmpRetDetail.respCode = "0";
//                                tmpRetDetail.respInfo = "";
//                                String response = tmpBkReader.getFirstText("/Transaction/Transaction_Body/response");
//                                if (StringHelper.isNullOrEmpty(response)) {
//                                    tmpRetDetail.signState = ContractState.UNSIGNED;
//                                }
//                                while (tmpBkReader.read("/Transaction/Transaction_Body/response/INST_GRP")) {
//                                    tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("TrdPCt_AccNo");
//                                    tmpRetDetail.payName = tmpBkReader.readedXElement.getSingleText("Acc_AccNm");
//                                    tmpRetDetail.certNum = tmpBkReader.readedXElement.getSingleText("Crdt_No");
//                                    String signState = tmpBkReader.readedXElement.getSingleText("SRP_AR_StCd");
//                                    if ("03".equals(signState)) {
//                                        tmpRetDetail.signState = ContractState.SUCCESS;
//                                    } else if ("11".equals(signState)) {
//                                        tmpRetDetail.signState = ContractState.SIGNING;
//                                    } else {
//                                        tmpRetDetail.signState = ContractState.FAIL;
//                                    }
//                                    tmpRetDetail.signConfirmType = "3";
//                                }
//                            } else {
//                                tmpRetDetail.respCode = "-1";
//                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/Transaction/Transaction_Header/tran_response/desc");
//                                tmpRetDetail.signState = ContractState.FAIL;
//                            }
//                        } else {
//                            tmpRetDetail.respCode = "-1";
//                            tmpRetDetail.respInfo = tmpStrRet[1];
//                        }
//                    } catch (Exception ex) {
//                        ex.printStackTrace();
//                        tmpRetDetail.respCode = "-1";
//                        tmpRetDetail.respInfo = ex.getMessage();
//                        WriteBankLogLn(ex);
//                    }
//                } else {
//                    tmpRetDetail.respCode = "-1";
//                    tmpRetDetail.respInfo = "签到失败";
//                }
//            } else {
//                tmpRetDetail.respCode = "-1";
//                tmpRetDetail.respInfo = "下载银行pub密钥失败";
//            }
//        } else {
//            tmpRetDetail.respCode = "-1";
//            tmpRetDetail.respInfo = "下载银行3des密钥失败";
//        }
//        retAts.writeRetDetail(tmpRetDetail);
//        return retAts;
//    }
//
//    @Override
//    public RetAtsQryBatContract qryBatContract(ReqQryBatContract p_reqQry) throws Exception {
//        return null;
//    }
//}
